package com.huangmb.androidlib.utils;

import android.content.Context;
import android.graphics.Point;
import android.view.WindowManager;

/**
 * 备注:
 *
 * @author hmb
 * @version 1.0
 * @since 2016/4/4 15:00
 */
public class ScreenUtils {
    private ScreenUtils() {
        throw new AssertionError();
    }

    public static float dp2pxFloat(Context context, float dp) {
        if (context == null) {
            return -1;
        }
        return dp * context.getResources().getDisplayMetrics().density;
    }

    public static float px2dpFloat(Context context, float px) {
        if (context == null) {
            return -1;
        }
        return px / context.getResources().getDisplayMetrics().density;
    }

    public static int dp2pxInt(Context context, float dp) {
        return (int)(dp2pxFloat(context, dp) + 0.5f);
    }

    public static int px2dpInt(Context context, float px) {
        return (int)(px2dpFloat(context, px) + 0.5f);
    }

   public static Point getScreenWidthAndHeight(Context context){
       WindowManager manager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
       Point p = new Point();
       manager.getDefaultDisplay().getSize(p);
       return p;
   }
}
